package com.webshop.app.entity;

import java.io.Serializable;
import java.util.HashSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
public class Category implements Serializable {
	
	@Id
	@GeneratedValue
	@Column
	private int id;
	@Column
	private String name;
	
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name ="fk_parent_catogry")
	private Category parentCategory;
	
	
	@OneToMany(mappedBy= "parentCategory", cascade= CascadeType.ALL)
	private java.util.Set<Category> subCategories = new HashSet<Category>();
	
	
	@OneToMany(targetEntity = Item.class, mappedBy = "category", 
			cascade=CascadeType.ALL, fetch = FetchType.EAGER)
	private java.util.Set<Item> itemsInCategory;
	
	public Category(){

	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Category getParentCategory() {
		return parentCategory;
	}

	public void setParentCategory(Category parentCategory) {
		this.parentCategory = parentCategory;
	}

	public java.util.Set<Category> getSubCategories() {
		return subCategories;
	}

	public void setSubCategories(java.util.Set<Category> subCategories) {
		this.subCategories = subCategories;
	}
	
	
	public java.util.Set<Item> getItemsInCategory() {
		return itemsInCategory;
	}

	public void setItemsInCategory(java.util.Set<Item> itemsInCategory) {
		this.itemsInCategory = itemsInCategory;
	}

	
}
